/**
 * Created by easy on 15/6/17.
 */
define(["jquery","MoCoop"],function ($,mc){
    var pagination = {};
    var scrollstatus = 0;
    pagination.lastScrollTime = 0;
    pagination.morePage = function(options){
        var execPagging = false;
        var dataLength = options.dataLength,
            scrollContainer = options.scrollContainer,
            callback = options.callback,
            loadingNoticeObj = options.loadingNoticeObj === undefined ? $(".mc-scroll-loading") : options.loadingNoticeObj,
            pageSize = options.pageSize,
            currentPage = options.currentPage;
        loadingNoticeObj.show().find(".mc-scroll-pomptlabel").html("加载中");
        scrollContainer.off("scroll").on("scroll",function () {//监听列表滚动事件
            if(mc.device === "iOS"){
                pagination.lastScrollTime = new Date().getTime();
            }
            var scrolltop = scrollContainer.scrollTop();//显示区域到顶部距离
            if (scrolltop <= 0) {//页面滚动为负值
                scrollstatus = 0;
            }
            if(scrolltop > 0){//页面滚动为正值
                scrollstatus = 1;
            }
            var innerheight = scrollContainer.innerHeight();//显示区域高度
            var scrollheight = scrollContainer[0].scrollHeight;//整个区域高度
            if ((parseInt(scrolltop)+parseInt(innerheight) >= scrollheight - 25) && execPagging === false) { //滑动到最底部时
                //scrollContainer.off('scroll');
                if(dataLength === pageSize){
                    callback();
                }
                execPagging = true;
            }
        });
        scrollContainer.siblings(".mc-nodata").hide();
        scrollContainer.find(".mc-nodata").hide();
        if(dataLength < pageSize){
            var pomptlabel;
            var judge = (currentPage === 2);
            if(judge){//当前是第一页
                if(dataLength === 0){
                    scrollContainer.siblings(".mc-nodata").fadeIn();
                    scrollContainer.find(".mc-nodata").fadeIn();
                    pomptlabel = "";
                    loadingNoticeObj.hide();
                }else{
                    pomptlabel = "";
                    loadingNoticeObj.hide();

                }
            }else{
                pomptlabel = "已无更多";
            }
            loadingNoticeObj.find(".mc-scroll-pomptlabel").html(pomptlabel);
        }
    };
    pagination.initScrollList = function(options){
        var loadingNoticeObj = options.loadingNoticeObj === undefined ? $(".mc-scroll-loading") : options.loadingNoticeObj,
            scrollContainer = options.scrollContainer;
        loadingNoticeObj.hide().find(".mc-scroll-pomptlabel").html("");
        scrollContainer.siblings(".mc-nodata").hide();
    };

   return pagination;
});
